#!/bin/bash

# 网站脚本前面必须这样写
echo "Content-Type:text/html;"
echo ""

echo '
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>学生列表</title>
    <link rel="stylesheet" href="/static/css/bootstrap.min.css">
</head>
<body>

<div class="container mt-5">
<h1 class="mb-4">学生列表</h1>

<table class="table table-bordered">
    <thead>
        <tr>
            <th>姓名</th>
            <th>学号</th>
            <th>班级</th>
            <th>年龄</th>
        </tr>
    </thead>
    <tbody>
'

lines=$(cat /etc/passwd|wc -l)
for ((i=1;i<=$lines;i++));do
        stu=$(cat /etc/passwd | sed -n $i"p")
        id=$(echo $stu | awk -F":" {'print $3}')
        name=$(echo $stu | awk -F":" {'print $1}')
        class=$(echo $stu | awk -F":" {'print $7}')
        age=$(echo $stu | awk -F":" {'print $4}')

        echo "
                <tr>
                        <td>$name</td>
                        <td>$id</td>
                        <td>$class</td>
                        <td>$age</td>
                </tr>
                <!-- 可根据需要添加更多的学生信息行 -->
        "
done
echo '
    </tbody>
</table>
</div>
<script src="/static/js/bootstrap.min.js"></script>
</body>
</html>
'

